package com.shinbada.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

/**
 * 请注意这里由于spring机制
 * 1. 项目中所有实现了 {@link CommandLineRunner} 接口的方法依次调用，如果首先调用的出现了问题，那么后面不会执行!!!
 * 2. {@link Order} 注解用来控制当前实现类被调用的顺序
 * 3. 目前项目中存在的依次为 :
 * {@link com.shinbada.core.security.shiro.SpringOpenApiProcessor}
 * {@link AppInit}
 *
 * @author initcap
 * @date 2021/1/24 21:04
 */
@Slf4j
@Order(value = 2)
@Component
public class AppInit implements CommandLineRunner {

    @Value("${server.port}")
    private String port;

    @Value("${server.servlet.context-path}")
    private String path;

    @Value("${spring.application.name}")
    private String name;

    @Override
    public void run(String... args) throws Exception {
        log.info(">>>>>>>>>>>>>>>{} 启动成功<<<<<<<<<<<<<", name);
        String ip = InetAddress.getLocalHost().getHostAddress();
        log.info("Application running at:\n\t" +
                        "- Local: http://localhost:{}{}/\n\t" +
                        "- Network: http://{}:{}{}/\n\t" +
                        "- swagger: http://{}:{}{}/doc.html\n" +
                        "----------------------------------------------------------",
                port, path, ip, port, path, ip, port, path);
    }

}

